package com.asset.salesforce.activities;

//import java.util.Random;

import com.asset.salesforce.R;
import com.asset.salesforce.chart.PieChart;
import com.asset.salesforce.chart.PieChart.OnSliceClickListener;


import android.os.Build;
import android.os.Bundle;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.Menu;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;

public class DashboardActivity extends Activity {
	@TargetApi(Build.VERSION_CODES.HONEYCOMB)
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dashboard);
		
		//final Random random = new Random();

		RelativeLayout layout = (RelativeLayout) findViewById(R.id.layout);
		//ScrollView scrollView = (ScrollView) findViewById(R.id.list_scroll);
		final PieChart p = new PieChart(this);
		LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	//	lp.height=10;lp.width = 100;
		p.setLayoutParams(lp);
		
		//p.setBackgroundColor(0xffffffff);
		p.setOnSliceClickListener(new OnSliceClickListener() {
			
			@Override
			public void onSliceClicked(PieChart pieChart, int sliceNumber) {
				Intent intent = null;
	              if(sliceNumber==0){
	            	  Toast.makeText(DashboardActivity.this,"Leads", Toast.LENGTH_SHORT).show();
	              intent = new Intent(getBaseContext(),LeadActivity.class);}
	              else if(sliceNumber==1){
	            	  Toast.makeText(DashboardActivity.this,"Accounts", Toast.LENGTH_SHORT).show();
	            	  intent = new Intent(getBaseContext(),AccountActivity.class);}
	              else if(sliceNumber==2){
	            	  Toast.makeText(DashboardActivity.this,"Contacts", Toast.LENGTH_SHORT).show();
	            	  intent = new Intent(getBaseContext(),ContactActivity.class);}
	              if(intent != null)
	  				startActivity(intent);
			}
		});
		float[] data = new float[3];
		for (int i = 0; i < data.length; i++) {
			data[i] = 2;
		} 
		p.setSlices(data);
		p.anima();
		//scrollView.addView(p);
		layout.addView(p);
		
		TableLayout t1 = (TableLayout) findViewById(R.id.list_table);
		 t1.setX(30);
		 t1.setY(800);
		    for (int i = 0; i < 10; i++) {
		        TableRow tr = new TableRow(this);
		        tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,
		                TableRow.LayoutParams.WRAP_CONTENT));           
		        t1.addView(tr, new TableLayout.LayoutParams(
		                TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));  
		        TextView tv = new TextView(this);
		        tr.addView(tv, new TableRow.LayoutParams(
		                TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
		        tv.setText(Integer.toString(i));
		        tv = new TextView(this);
		        tr.addView(tv, new TableRow.LayoutParams(
		                TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
		        tv.setText("Leads");
		        tv = new TextView(this);
		        tr.addView(tv, new TableRow.LayoutParams(
		                TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
		        tv.setText(Integer.toString(i));        
		    }
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
